<template>
  <div>
    <el-dialog :fullscreen="fullscreen" append-to-body :visible.sync="isShow3" width="700px" :show-close="false" :before-close="parentCloseEvent" top="3%">
        <el-row slot="title">
            <el-col :span="10" style="padding-top: 5px">
                <span>社区管理</span>
            </el-col>
            <el-col :span="2" :offset="11">
                <el-button type="text" v-if="!fullscreen" icon="iconfont ali-quanping" @click="fullscreen = true" style="float: right"></el-button>
                <el-button type="text" v-else icon="iconfont ali-zuixiaohua" @click="fullscreen = false" style="float: right"></el-button>
            </el-col>
            <el-col :span="1">
                <el-button type="text" icon="iconfont ali-guanbi" @click="parentCloseEvent" style="float: right"></el-button>
            </el-col>
        </el-row>
        <!-- 工具栏 -->
        <section class="filter-container">
            <el-button class="filter-item" type="primary" @click="deleData">删除</el-button>
        </section>
        <!-- 表格 -->
    <el-table :data="tableList" v-loading="loading" element-loading-text="正在查询中。。。" stripe highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column align="center" width="30">
        <template slot-scope="scope">
          <i class="iconfont ali-zhiding" v-show="scope.row.top_status == 1"></i>
        </template>
      </el-table-column>
      <el-table-column align="center" label="主题" show-overflow-tooltip>
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="lookArticle(scope.row)">{{scope.row.article_title}}</el-button>
        </template>
      </el-table-column>
      <el-table-column align="center" label="作者" prop="create_username">
      </el-table-column>
      <el-table-column align="center" label="发布时间" prop="create_time">
      </el-table-column>
      <el-table-column align="center" label="评论量" prop="comment_nums">
      </el-table-column>
      <el-table-column align="center" label="点赞量" prop="like_nums">
      </el-table-column>
      <el-table-column align="center" label="浏览量" prop="browse_nums">
      </el-table-column>
      <el-table-column align="center" label="详情链接">
        <template slot-scope="scope">
          <el-button
            v-clipboard:copy="'https://cloud.anyolife.com/CommunityDetail' + '?id=' + scope.row.id + '&name=' + 'article'"
            v-clipboard:success="onCopy"
            v-clipboard:error="onError"
            type="text"
          >复制链接</el-button>
        </template>
      </el-table-column>
    </el-table>
        <!-- 分页 -->
        <section>
          <so-pagination :query="listQuery" @initList="initList"/>
        </section>
    </el-dialog>
  </div>
</template>
<script>
import SoPagination from "@/components/SoPagination";
import { communityManager_list, communityManager_deleteAll } from '@/api/communityManage'

import { status_opt, t_active, t_status, toolData } from "../activity";

export default {
  components: {
    SoPagination
  },
  props: {
      isShow3: {
          type: Boolean,
          default: false
      }
  },
  data() {
      return {
            listQuery: { start: 0, limit: 10, total: 0, current: 1 },
            tableList: [],
            loading: false,
            multipleSelection: [],
            t_active: t_active,
            t_status: t_status,
            status_opt: status_opt,
            fullscreen: false
      }
  },
    methods: {
        onCopy: function() {
            this.$message({
            type: "success",
            message: "复制成功"
            });
        },
        onError: function() {
            this.$message.error("复制失败");
        },
        async deleData(){
            this.$emit("editcommunity", this.multipleSelection)
            if(this.multipleSelection.length===0){
               this.$message.warning("请先选择需要删除的数据");
               return;
            }
            let ids = this.multipleSelection.map(item => item.id).join();
            try {
              let res = await this.$confirm("确定要删除吗？");
              if(res=="confirm"){
                this.loadingc = true;
                const {data} = await communityManager_deleteAll({array: ids});
                if(data.status==100){
                  this.$message.success("删除成功");
                }
                this.initList();
              }
            } catch (error) {
              this.$message.error('删除失败');
            }

        },
        async fmtDiffList(community, ){},
        async initList(){
            this.loading = true;
            const query = {
              ...this.listQuery, company_id: localStorage.getItem("companyId") - 0,
              pageSet_id: sessionStorage.getItem("pageSetRow_Id") - 0,
              organization_id: sessionStorage.getItem("organization_id") - 0, 
            };
            let {data } = await communityManager_list(query);
            this.loading = false;
            if(data.status === 100){
                this.tableList = data.data.rows;
                
            }
        },
        handleSelectionChange(e) {
            this.multipleSelection = e;
        },
        parentCloseEvent() {
            this.$emit('closeTemp');
        },
    },
};
</script>